home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / haeberli / impression / sspntgen.c < prev    next >
C/C++ Source or Header  |  1994-08-01  |  2KB  |  105 lines

  1. /*
  2.  * Copyright 1991, 1992, 1993, 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. /*
  18.  *    ssgen - 
  19.  *        Use a set of point sample locations to generate a 
  20.  *    sample set.
  21.  *
  22.  *            Paul Haeberli - 1989
  23.  */
  24. #include "stdio.h"
  25. #include "ss.h"
  26. #include "math.h"
  27.  
  28. int npoints;
  29. float xpoints[100];
  30. float ypoints[100];
  31.  
  32. main(argc,argv)
  33. int argc;
  34. char **argv;
  35. {
  36.     sampleset *oss;
  37.     int nx, ny;
  38.  
  39.     if( argc<5 ) {
  40.     fprintf(stderr,"usage: ssgen in.pnts out.ss nx ny\n");
  41.     exit(1);
  42.     } 
  43.     readpoints(argv[1]);
  44.     nx = atoi(argv[3]);
  45.     ny = atoi(argv[4]);
  46.     oss = ssnew();
  47.     sspntsgen(oss,nx,nx);
  48.     sstofile(argv[2],oss);
  49. }
  50.  
  51. sspntsgen(oss,nx,ny)
  52. sampleset *oss; 
  53. int nx, ny;
  54. {
  55.     sample *ns;
  56.     float xpos, ypos;
  57.     int i, x, y;
  58.     float bx, by, sx, sy;
  59.  
  60.     sx = 1.0/nx;
  61.     sy = 1.0/ny;
  62.     for(y=0; y<nx; y++) {
  63.     for(x=0; x<nx; x++) {
  64.         bx = (float)x/nx;
  65.         by = (float)y/ny;
  66.         for(i=0; i<npoints; i++) {
  67.         xpos = bx + sx*xpoints[i];
  68.         ypos = by + sy*ypoints[i];
  69.         ns = (sample *)malloc(sizeof(sample));
  70.         ns->xpos = POSSCALE*xpos;
  71.         ns->ypos = POSSCALE*ypos;
  72.         ns->r = 0;
  73.         ns->g = 0;
  74.         ns->b = 0;
  75.         ns->a = 0;
  76.         ns->SAMPLE_SIZE = 60;
  77.         ns->SAMPLE_DIR = -256/8;
  78.         ns->SAMPLE_SHAPE = FINELINES;
  79.         addsample(oss,ns);
  80.         }
  81.     }
  82.     }
  83. }
  84.  
  85. readpoints(name)
  86. char *name;
  87. {
  88.     FILE *inf;
  89.     int i;
  90.     float x, y;
  91.  
  92.     inf = fopen(name,"r");
  93.     if(!inf) {
  94.     fprintf(stderr,"sspntgen: can't open input file\n");
  95.     exit(1);
  96.     }
  97.     fscanf(inf,"%d\n",&npoints);
  98.     for(i=0; i<npoints; i++) {
  99.     fscanf(inf,"%f %f\n",&x,&y);
  100.     xpoints[i] = x;
  101.     ypoints[i] = y;
  102.     }
  103.     fclose(inf);
  104. }
  105.